<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增contaxx系列')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-contaxx-add">
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text">
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">尺寸分类：</label>
                <div class="col-sm-8">
                    <select name="size" class="form-control" th:with="type=${@dict.getType('contaxx_size2')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">场景：</label>
                <div class="col-sm-8">
                    <select name="scene" class="form-control" th:with="type=${@dict.getType('contaxx_scene')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">风格：</label>
                <div class="col-sm-8">
                    <select name="style" class="form-control" th:with="type=${@dict.getType('contaxx_style')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">上传图片：</label>
                    <div class="col-sm-8">
                        <input type="file" name="imageFile" id="imageFile" class="form-control" accept="image/*" onchange="convertImageToBase64()" />
                        <!-- 隐藏的文本域，用于存放图片的base64 -->
                        <input type="hidden" name="img" id="imgBase64" class="form-control">
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">花纹：</label>
                <div class="col-sm-8">
                    <select name="figure" class="form-control" th:with="type=${@dict.getType('contaxx_figure')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">普通价格：</label>
                <div class="col-sm-8">
                    <input name="price" class="form-control" type="text">
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">会员价格：</label>
                <div class="col-sm-8">
                    <input name="priceVip" class="form-control" type="text">
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">库存：</label>
                <div class="col-sm-8">
                    <input name="inventory" class="form-control" type="text">
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">简介：</label>
                <div class="col-sm-8">
                    <input name="synopsis" class="form-control" type="text">
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">详细介绍：</label>
                <div class="col-sm-8">
                    <textarea name="introduce" class="form-control"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    function convertImageToBase64() {
        var file = document.getElementById("imageFile").files[0];
        var reader = new FileReader();

        reader.onloadend = function () {
            // 将base64字符串赋值给隐藏的文本域
            document.getElementById("imgBase64").value = reader.result;
        };

        if (file) {
            reader.readAsDataURL(file); // 读取文件并转换为base64
        }
    }

    var prefix = ctx + "system/contaxx"
    $("#form-contaxx-add").validate({
        onkeyup: false,
        rules:{
            price:{
                number: true
            },
            priceVip:{
                number: true
            },
            inventory:{
                digits: true
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-contaxx-add').serialize());
        }
    }
</script>
</body>
</html>
